#include <iostream>
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
long num = 0;
boost::mutex num_mutex;
void numplus() {
    //num_mutex.lock();
    std::cout << "numplus  in" << std::endl;
    boost::lock_guard<boost::mutex> lock_guard(num_mutex);
    for (long i = 0; i < 1000000; ++i) {
        num++;
    }
    std::cout << "numplus finishing" << std::endl;
    //num_mutex.unlock();
};

void numsub() {
    std::cout << "numsub  in" << std::endl;
    boost::lock_guard<boost::mutex> lock_guard(num_mutex);
    std::cout << "numsub start" << std::endl;
    for (long i = 0; i < 1000000; ++i) {
        num--;
    }
    std::cout << "numsub finishing" << std::endl;
    //num_mutex.unlock();
}

int main(void) {
    boost::thread t1(numplus);
    boost::thread t2(numsub);
    t1.join();
    t2.join();
    std::cout << num << std::endl;
    return 0;
}